package com.cqndt.disaster.device.common.aspect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.core.annotation.Order;
import com.cqndt.disaster.device.common.annotation.DataSource;
import com.cqndt.disaster.device.common.datasource.DataSourceContextHolder;

@Order(1)
@Aspect
@Component
public class DataSourceAspect {
	
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Before("@annotation(ds)")
    public void beforeDataSource(DataSource ds) {
        // 修改为String
        String value = ds.value().getDb();
        DataSourceContextHolder.setDataSource(value);
        logger.info("当前使用的数据源为：{}", value);
    }
    @After("@annotation(ds)")
    public void afterDataSource(DataSource ds){
        DataSourceContextHolder.clearDataSource();
    }
}